﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using CNStreaming;
using CNUtility;

namespace CNShapes
{
    /// <summary>
    /// This "shape" acts as a pointer. It lets you point to a point on the
    /// screen, and the pointer can be seen by other people connected across
    /// the network.
    /// </summary>
    public class Shape_Pointer : Shape
    {
        #region Shape members

        /// <summary>
        /// Returns the bounds of this shape.
        /// </summary>
        public override RectangleF getBounds(Graphics graphics)
        {
            return new RectangleF(m_PointerPosition.X - 2, m_PointerPosition.Y - 2, 5, 5);
        }

        #endregion

        #region Public methods

        /// <summary>
        /// Returns the position of the pointer.
        /// </summary>
        public PointF getPointerPosition()
        {
            return m_PointerPosition;
        }

        /// <summary>
        /// Sets the position of the pointer.
        /// </summary>
        public void setPointerPosition(PointF pointerPosition, ActionOrigin actionOrigin)
        {
            // We update the point and raise the shape-completed event.
            // We raise this event (rather than the shape-edited event) as this
            // will trigger an update of the shape across the network.
            m_PointerPosition = pointerPosition;
            raiseShapeEditCompletedEvent(actionOrigin);
        }

        #endregion

        #region IStreamable methods

        /// <summary>
        /// Returns the message version.
        /// </summary>
        public override int getMessageVersion()
        {
            return 1;
        }

        /// <summary>
        /// Serializes this class's data to the stream passed in.
        /// </summary>
        public override void toStream(MessageStream stream)
        {
            base.toStream(stream);
            stream.writePointF(m_PointerPosition);
        }

        /// <summary>
        /// Reads this object's data from the stream passed in.
        /// </summary>
        public override void fromStream(MessageStream stream, int iVersion)
        {
            base.fromStream(stream, iVersion);
            m_PointerPosition = stream.readPointF();
        }

        #endregion

        #region Private data

        // The location of the pointer...
        private PointF m_PointerPosition = new PointF();

        #endregion
    }
}
